#ifndef __SGCONF_H__
#define __SGCONF_H__

#include <stdint.h>
#include <netinet/in.h>
#include <openssl/blowfish.h>

#include <string>

class SGCONF {
    public:
        SGCONF();
        ~SGCONF();

        bool SetHost(const std::string & h);
        void SetPort(uint16_t p) { remoteAddr.sin_port = htons(p); };
        void SetLogin(const std::string & l) { login = l; };
        void SetPassword(const std::string & p) { password = p; };

        bool Perform(const std::string & xml);
        bool GetAnswer(std::string & xml) const;

        const std::string & GetResult() const { return result; };
        const std::string & GetStrError() const { return errorStr; };

    private:
        int sd;
        struct sockaddr_in remoteAddr;
        std::string login;
        std::string password;
        std::string errorStr;
        std::string result;
        bool hostOk;

        mutable unsigned char * iv;

        BF_KEY key;

        bool ReadBlock(void * dest, size_t & size, int timeout) const;
        bool WriteBlock(const void * source, size_t & size, int timeout) const;

        bool Connect();
        bool WriteXML(const std::string & xml) const;

};

#endif
